home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000018_icon-group-sender _Tue Jul 20 21:35:06 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
2KB
Received: by cheltenham.cs.arizona.edu; Tue, 20 Jul 1993 19:44:55 MST
Date: Tue, 20 Jul 93 21:35:06 EDT
From: Paul_Abrahams@MTS.cc.Wayne.edu
To: icon-group@cs.arizona.edu
Message-Id: <706461@MTS.cc.Wayne.edu>
Subject: Mysteries of "every"
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
Cary Coutant wrote the following in response to my query:
-----------------------------
> every retval := 8 * retval + ord(!s) - ord("0")
>
> Now the output of the program is 3 (the last digit), not 83.
>
> Can anyone explain to me what's going on?
Try reversing the operands of the "+" operation:
every retval := ord(!s) - ord("0") + 8 * retval
Your problem was that the every was resuming the expression
from the last suspended generator, so "8 * retval" was never
being reevaluated.
In situations like this, it's sometimes useful to replace a
built-in operator with your own procedure, so you can see
what's going on by setting TRACE. For example:
every retval := add(8 * retval, ord(!s) - ord("0"))
-----------------------------------
This explanation satisfies the ultimate test: Cary's version works.
Yet I've looked again at pages 15-16 of the Icon book and I still don't
get it. The explanation of resumption on p. 15 is in terms of failure,
and there's no failure in the expression of my example. The description
of "every" on p. 16 says that "expr1 is first evaluated and then
repeatedly resumed to produce all its values." I would have thought that
resuming an expression that doesn't fail would cause it to be
=completely= reevaluated.
Clearly the assignment, which is the outermost level of the expression,
is evaluated on each iteration. In fact, I verified (by attaching a
"do") that with s="123", retval takes on successive values of 1,2,3. Yet
the second retval is not being reevaluated. So which parts of an
expression are reevaluated and which ones aren't? Is there any way to
deduce what happens from the explanation in the Icon book?
I'd appreciate any help I can get on this. I'd also suggest that you
post your comments to icon-group rather than sending them to me
personally.
Paul Abrahams
Reply-To: abrahams@acm.org